/**
 * @file      semaphore.h
 * @copyright Copyright (c) 2020, ZCW Co., Ltd. All Rights Reserved.
 * @brief     brief
 * @author    caiwang213@qq.com
 * @date      2020-12-21 00:50:52
 *
 * @note
 *  semaphore.h. It will conflict with system header file <semaphore.h>
 */
#ifndef __SEMAPHORE_H__
#define __SEMAPHORE_H__
#include "mutex.h"
#include <condition_variable>

typedef std::condition_variable cv_t;

namespace log4x
{
class Semaphore
{
    CLASS_NO_COPY(Semaphore)
public:
    Semaphore(long count = 0);
    ~Semaphore();

public:
    void               post();
    int                wait(int msec);

private:
    std::mutex         _mutex;
    cv_t               _cv;
    long               _count;
};
}
#endif
